<?php
class DatabaseAction extends Action{
	public function create_sqlite(){
		try{
			//创建文件夹
			$path=C('PATH_SQLITE_DATABASE');
			if(!is_dir($path)) mkdir($path,0777,true);
			$path.=time().rand(1,10000).'.db';
			//删除原有文件夹
			exec("rm -rf {$path}");
			$dbh=new PDO("sqlite:{$path}");
			$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			
			/*event 事件*/
			$sql  = "CREATE TABLE event(
				event_id integer PRIMARY KEY,
				event_name Varchar DEFAULT NULL,
				event_description TEXT,
				event_startTime integer,
				event_endTime integer,
				event_launch_id integer,
				event_execution_id integer,
				event_examination_id integer,
				event_acceptance_id integer,
				event_launch_name Varchar,
				event_execution_name Varchar,
				event_examination_name Varchar,
				event_acceptance_name Varchar,
				event_state integer,
				project_id integer,
				time_insert integer
			);";
			/*project 项目*/
			$sql  = "CREATE TABLE event(
				project_id integer PRIMARY KEY,
				project_name Varchar DEFAULT NULL,
				project_description TEXT,
				project_startTime integer,
				project_endTime integer,
				project_head_id integer,
				project_head_name integer,
				time_insert integer
			);";
			
			$dbh->exec($sql);
			D('Database')->save_sqlite_path($path);
			echo '{"state":0}';
		}catch(Exception $e) {
			echo '{"state":-1}';
		}	
	}	
}

?>